<template>
	<view>
		<view class="top bgw p30">
			<view>充值账户</view>
			<input v-model="phone" type="number" maxlength="11" placeholder="请输入需要充值的账户" />
			<image @tap="phone = ''" class="demoves" src="../../static/image/icon_quxiao@2x.png"></image>
		</view>
		<view class="main bgw p30">
			<p class="title">充值金额</p>
			<view class="money ">
				<view>￥</view>
				<input @blur="numCheCking()" maxlength="7" type="number" v-model="money" placeholder="请输入您要充值的金额" />
			</view>
			<textarea maxlength="20" class="text-df" v-model="remarks" placeholder="添加备注（20字以内）" />
			</view>
		<view class="btn p30"><button @tap="checking()" class="btnbg text-lg">确认充值</button></view>
		<view v-if="models == 0" @tap="models = 1" class="model">
			<view @tap.stop class="boxs  bgw">
				<view class="title">
					<image @tap="models = 1" class="quxiao" src="../../static/image/quxiao1.png" mode=""></image>
					确认充值
				</view>
				<view class="txt">
					<p class="p1">
						<span>￥</span>
						{{ this.money }}
					</p>
					<p class="p2">充值账户：{{ this.phone }}</p>
				</view>
			</view>
			<button @tap="modelss()" class="btnbg text-lg">确定</button>
		</view>
	</view>
</template>

<script src="./base64.js"></script>
<script>
import { recharge, cardPay, scanCode } from '@/api/api.js'; 
export default {
	data() {
		return {
			shakeState:0,
			models: 1,
			money: '',
			phone: '',
			remarks: ''
		};
	},
	onShow() {
		this.phone = '';
		this.money = '';
		this.remarks = '';
		this.shakeState = 0
	},
	methods: {
		numCheCking() {
			this.money = Math.round(this.money * 100) / 100;
			if (this.money == 0) {
				this.money = '';
			}
		},
		checking() {
			this.money = Math.round(this.money * 100) / 100;
			if (this.money == 0) {
				this.money = '';
			}
			try {
				if (!/^1[3456789]\d{9}$/.test(this.phone)) throw '手机号不符合规范';
				if (this.money == '') throw '请填写金额';
				if (this.money <= 0) throw '金额要大于0';
			} catch (err) {
				this.toa(err);
				return;
			} 
			this.models = 0
		},
		modelss() {
			this.models = 1;
			if(this.shakeState == 0){
				this.shakeState = 1
				this.send();		
			} 
		},
		async send() {
			let data = {
				mobile: this.phone,
				money: this.money,
				remarks: this.remarks
			};
			let datas = await recharge(data); 
			 let parameter ={
				 code:datas.code,
				 msg:datas.msg,
				 mobile: this.phone,
				 money: this.money,
				 remarks: this.remarks
			 }
			 uni.setStorageSync('payData',parameter)
			 uni.navigateTo({
			 	url:'../rechargeType/rechargeType'
			 })
			 this.shakeState = 0
		},
		toa(txt) {
			uni.showToast({
				title: txt,
				icon: 'none'
			});
		}
	}
};
</script>

<style lang="less" scoped>
@import './index.less';
</style>
